home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS in a Box 7
/
BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso
/
Files
/
Tele
/
C
/
Comet2.1.3.cpt
/
emlib
/
prettywind.c
< prev
next >
Wrap
Text File
|
1991-04-01
|
16KB
|
791 lines
/*
Copyright Cornell University 1986. All rights are reserved.
prettywind.c routines handle drawing of the window frame,
status labels, .
(emcursor.c routines handle drawing and manipulatation of the q3 controls.)
*/
#include <em.h>
#include <h19.h>
#include <rcodes.h>
#include <resdefs.h>
Rect largerect;
RgnHandle soldclip; /* for save/restore functions */
short oldfontsize; /* for save/restore functions */
#define saveclip()
#define restoreclip()
/* these defines set the top/bottom rectangle for the above label rects */
#define PWLEFTMARG 486
#define PWRIGHTMARG 497
#define PWSHRINKTOP 10
#define PWSHRINKBOT 33
#define PWSYSLOCKTOP 60
#define PWSYSLOCKBOT 97
#define PWKBDLOCKTOP 110
#define PWKBDLOCKBOT 147
#define PWSHIFTTOP 160
#define PWSHIFTBOT 197
#define PWRECORDTOP 219 /* picture of tape cassette indicating record mode */
#define PWRECORDBOT 230
#define PWDUBSHIFTTOP 236
#define PWDUBSHIFTBOT 276
#define PWMACROTOP 276
#define PWMACROBOT 287
/* draw the window frame, title, controls, and various labels we need;
assumes window pointer is set */
prettywind(drawcontrols)
{
char achar;
short count;
Rect fillrect;
Rect paintrect;
short xpos, ypos;
struct fontsave ofont;
RGBColor forecolor;
savefont(&ofont);
saveclip();
if (emdp->color) {
/* fill the screen with the normal background color */
paintrect.top = -5;
paintrect.left = -3;
paintrect.bottom = emwindow->portRect.bottom;
paintrect.right = emdp->h19right - 7;
GetForeColor(&forecolor);
RGBForeColor(&emdp->ibmcolormap.colors[1]); /* normal background */
PaintRect(&paintrect);
RGBForeColor(&forecolor);
}
/* top */
MoveTo((short) -10, (short) -29);
Line((short) 1000, (short) 0);
/* double line at top */
MoveTo((short) -10, (short) -5);
LineTo((short) 1000, (short) -5);
/* line at top of h19 screen */
/* gray out the top as a background for buttons */
if ( ! line25on(emdp) && (emdp->controlschanged || !emdp->dsdraw)) {
/* the buttons can be shared with prompts, if the prompts are on,
don't gray it out */
FillRect(&emdp->toprect, gray);
}
/* draw a title over the top, if there is one
if (!drawcontrols) {
count = strlen(screentitle);
pr25(35 - (count/2), screentitle);
}
*/
/* left */
if (drawcontrols) {
/* draw question mark button */
MoveTo((short) -9, (short) -12);
DrawChar('?');
/* draw 3rd quadrant buttons */
/* bottom - top == 20, * 12 boxes == height of window */
showq3buttons();
}
else {
/* gray the left side out */
fillrect.top = -30;
fillrect.left = -10;
fillrect.bottom = 300;
fillrect.right = -3; /* was -3 */
FillRect(&fillrect, gray);
}
MoveTo((short) -3, (short) -30);
Line((short) 0, (short) 1000);
/* line at right edge of 3rd quad buttons */
/* bottom */
MoveTo((short) (emdp->h19right - 7), (short) -5);
Line((short) 0, (short) 1000);
/* line at right edge, forming box for status lights/shrink button */
restoreclip();
restorefont(&ofont);
/* draw the other flags -- must be outside of previous save/restore clip */
showshrink();
if (emdp->pfshift)
pfshowshift();
showtape();
if (emdp->dokeymacros)
showmacroflag();
#ifdef SHOWDOUBLESHIFT
/* IBM PF double shift is not used, so... use the space for Macro label */
if (emdp->pfdubshift)
pfshowdubshift();
#endif
}
/* display a number in the left side of the right end of the top control bar */
drawversion(verstr)
char * verstr;
{
RgnHandle oldclip;
GrafPtr oport;
if (emwindow == NULL)
return;
GetPort(&oport);
SetPort(emwindow);
/* reset clip to area we're drawing in */
oldclip = NewRgn();
GetClip(oldclip);
ClipRect(&emdp->countrect);
EraseRect(&emdp->countrect);
/* draw box around input and output packet counters */
MoveTo((short) (emdp->countrect.left + 1), emdp->countrect.top);
LineTo((short) (emdp->countrect.left + 1), (short) -5); /* double line at left too */
FrameRect(&emdp->countrect);
SetClip(oldclip);
DisposeRgn(oldclip);
SetPort(oport);
}
/* display a number (packets received)
in the right side of the right end of the top control bar */
drawincount()
{
char scount[11];
RgnHandle oldclip;
GrafPtr oport;
struct fontsave ofont;
if (emwindow == NULL)
return;
/* reset clip to area we're drawing in */
GetPort(&oport);
SetPort(emwindow);
oldclip = NewRgn();
GetClip(oldclip);
savefont(&ofont);
ClipRect(&emdp->incountrect);
/* EraseRect(&emdp->incountrect); */
MoveTo((short) (emdp->incountrect.left + 3), (short) -12);
if (emdp->conntype == CONN_MACTCP || emdp->conntype == CONN_CUTCP)
/* # of packets */
sprintf(scount, "%10D", emdp->in_cnt);
else
/* # of kilo-chars */
sprintf(scount, "%10D", emdp->kin_cnt);
DrawText(scount, 5, 5);
restorefont(&ofont);
SetClip(oldclip);
DisposeRgn(oldclip);
SetPort(oport);
}
/* display a number (output packet count)
in the left side of the right end of the top control bar */
drawoutcount()
{
long count;
char scount[11];
RgnHandle oldclip;
struct fontsave ofont;
GrafPtr oport;
if (emwindow == NULL)
return;
if (emdp->resending) {
drawinvoutcount();
return;
}
count = emdp->out_cnt;
/* reset clip to area we're drawing in */
GetPort(&oport);
SetPort(emwindow);
oldclip = NewRgn();
GetClip(oldclip);
savefont(&ofont);
ClipRect(&emdp->outcountrect);
/* EraseRect(&emdp->outcountrect); */
MoveTo((short) (emdp->outcountrect.left + 3),(short) -12);
sprintf(scount, "%10D", count);
DrawText(scount, (short) 5, (short) 5);
restorefont(&ofont);
SetClip(oldclip);
DisposeRgn(oldclip);
SetPort(oport);
}
/* display a number (output packet count)
in the left side of the right end of the top control bar */
drawinvoutcount()
{
long count;
char scount[11];
RgnHandle oldclip;
struct fontsave ofont;
GrafPtr oport;
if (emwindow == NULL)
return;
count = emdp->out_cnt;
/* reset clip to area we're drawing in */
GetPort(&oport);
SetPort(emwindow);
oldclip = NewRgn();
GetClip(oldclip);
savefont(&ofont);
ClipRect(&emdp->outcountrect);
/* EraseRect(&emdp->outcountrect); */
MoveTo((short) (emdp->outcountrect.left + 3),(short) -12);
sprintf(scount, "%10D", count);
TextMode(notSrcCopy); /* invert the font */
DrawText(scount, (short) 5, (short) 5);
TextMode(srcCopy);
restorefont(&ofont);
SetClip(oldclip);
DisposeRgn(oldclip);
SetPort(oport);
}
/* initialize the shrink rectangle */
/* draw a collapsing rectangle a la the Zoom Box */
showshrink()
{
Rect shrinkt;
saveclip();
DrawPicture(shrinkpict, &emdp->shrinkrect);
restoreclip();
}
/* draw a collapsing rectangle a la the Zoom Box */
showtape()
{
Rect taperect;
taperect.top = PWRECORDTOP;
taperect.left = emdp->h19flagcenter - 4;
taperect.bottom = PWRECORDBOT;
taperect.right = taperect.left + 13;
saveclip();
if (emdp->logsession)
DrawPicture(tapepict, &taperect);
else
EraseRect(&taperect);
restoreclip();
}
/* display pf shift on */
pfshowshift()
{
struct fontsave ofont;
savefont(&ofont);
saveclip();
FrameRect(&emdp->shiftrect);
MoveTo(emdp->h19flagcenter, (short) (PWSHIFTTOP + 10));
DrawChar('^');
MoveTo(emdp->h19flagcenter, (short) (PWSHIFTTOP + 19));
DrawChar('P');
MoveTo(emdp->h19flagcenter, (short) (PWSHIFTTOP + 30));
DrawChar('F');
restoreclip();
restorefont(&ofont);
}
/* clear pf shift display */
pfclrshift()
{
saveclip();
EraseRect(&emdp->shiftrect);
restoreclip();
}
/* show a pf double shift on the display */
showaltmacro()
{
struct fontsave ofont;
savefont(&ofont);
saveclip();
MoveTo(emdp->h19flagcenter, (short) (PWDUBSHIFTTOP + 10));
DrawChar('A');
MoveTo(emdp->h19flagcenter, (short) (PWDUBSHIFTTOP + 21));
DrawChar('l');
MoveTo(emdp->h19flagcenter, (short) (PWDUBSHIFTTOP + 32));
DrawChar('t');
if (emdp->macroexecuting)
InvertRect(&emdp->dubshiftrect);
else
FrameRect(&emdp->dubshiftrect);
restoreclip();
restorefont(&ofont);
}
/* clear the macro ALT flag from the display */
clraltmacro()
{
saveclip();
EraseRect(&emdp->dubshiftrect);
restoreclip();
}
/* display macro interpretation on */
showmacroflag()
{
struct fontsave ofont;
if (emdp->keyaltset)
showaltmacro();
else
clraltmacro();
savefont(&ofont);
saveclip();
EraseRect(&emdp->macrorect);
TextMode(srcOr);
MoveTo(emdp->h19flagcenter, (short) (PWMACROTOP + 9));
DrawChar('M');
if (emdp->macroexecuting)
InvertRect(&emdp->macrorect);
else
FrameRect(&emdp->macrorect);
TextMode(srcCopy);
restoreclip();
restorefont(&ofont);
}
/* clear macro on display */
clrmacroflag()
{
clraltmacro();
saveclip();
EraseRect(&emdp->macrorect);
restoreclip();
}
showsyslock()
{
struct fontsave ofont;
savefont(&ofont);
saveclip();
FrameRect(&emdp->syslockrect);
MoveTo(emdp->h19flagcenter, (short) (PWSYSLOCKTOP + 10));
DrawChar('S');
MoveTo(emdp->h19flagcenter, (short) (PWSYSLOCKTOP + 21));
DrawChar('Y');
MoveTo(emdp->h19flagcenter, (short) (PWSYSLOCKTOP + 32));
DrawChar('S');
restoreclip();
restorefont(&ofont);
}
clrsyslock()
{
saveclip();
EraseRect(&emdp->syslockrect);
restoreclip();
}
showkbdlock()
{
struct fontsave ofont;
/* display keyboard locked */
savefont(&ofont);
saveclip();
FrameRect(&emdp->kbdlockrect);
MoveTo(emdp->h19flagcenter, (short) (PWKBDLOCKTOP + 10));
DrawChar('K');
MoveTo(emdp->h19flagcenter, (short) (PWKBDLOCKTOP + 21));
DrawChar('B');
MoveTo(emdp->h19flagcenter, (short) (PWKBDLOCKTOP + 32));
DrawChar('D');
restoreclip();
restorefont(&ofont);
}
clrkbdlock()
{
saveclip();
EraseRect(&emdp->kbdlockrect);
restoreclip();
}
#ifdef NEEDED
/* open the clip region wide open for drawing */
saveclip()
{
GetClip(soldclip);
ClipRect(&largerect);
}
restoreclip()
{
SetClip(soldclip);
}
#endif
/* save the current font size */
savefont(ofont)
struct fontsave * ofont;
{
ofont->fontsize = ((GrafPtr) emwindow)->txSize;
ofont->fontid = ((GrafPtr) emwindow)->txFont;
TextSize(9);
TextFont(202); /* our bold font CUB 9 */
}
/* restore the current font size */
restorefont(ofont)
struct fontsave * ofont;
{
TextSize(ofont->fontsize);
TextFont(ofont->fontid);
}
prettyinit()
{
if (soldclip == (RgnHandle) NULL)
soldclip = NewRgn();
largerect.top = -5000;
largerect.left = -5000;
largerect.bottom = 5000;
largerect.right = 5000;
/* question mark box for triggering label draw */
emdp->qmarkrect.top = -28;
emdp->qmarkrect.left = -12;
emdp->qmarkrect.bottom = -4;
emdp->qmarkrect.right = -3;
/* emdp->shrinkrect control */
emdp->shrinkrect.top = PWSHRINKTOP;
emdp->shrinkrect.left = 485;
emdp->shrinkrect.bottom = PWSHRINKBOT;
emdp->shrinkrect.right = 498;
emdp->h19right = 490; /* right end of line at top of em area */
emdp->h19flagcenter = 489;
/* rectangle for the Enter, Clear, etc. buttons at the top */
emdp->toprect.top = -28;
emdp->toprect.left = -2;
emdp->toprect.bottom = -5;
emdp->toprect.right = 427;
emdp->toprectbm.baseAddr = NewPtr(1920L);
emdp->toprectbm.rowBytes = 80;
emdp->toprectbm.bounds.top = 0;
emdp->toprectbm.bounds.left = 0;
emdp->toprectbm.bounds.bottom = 24;
emdp->toprectbm.bounds.right = 640;
/* rectangle for the counters */
emdp->countrect.top = -28;
emdp->countrect.left = 427;
emdp->countrect.bottom = -5;
emdp->countrect.right = 499;
/* the blanking rectangles for input and output counts */
emdp->incountrect.top = -20; /* -27 */
emdp->incountrect.left = 462;
emdp->incountrect.bottom = -10; /* -7 */
emdp->incountrect.right = 497;
emdp->outcountrect.top = -20; /* -27 */
emdp->outcountrect.left = 429;
emdp->outcountrect.bottom = -10; /* -7 */
emdp->outcountrect.right = 462;
/* initialize rectangles which frame items on the right */
emdp->shiftrect.top = PWSHIFTTOP;
emdp->shiftrect.left = PWLEFTMARG;
emdp->shiftrect.bottom = PWSHIFTBOT;
emdp->shiftrect.right = PWRIGHTMARG;
emdp->dubshiftrect.top = PWDUBSHIFTTOP;
emdp->dubshiftrect.left = PWLEFTMARG;
emdp->dubshiftrect.bottom = PWDUBSHIFTBOT;
emdp->dubshiftrect.right = PWRIGHTMARG;
emdp->macrorect.top = PWMACROTOP;
emdp->macrorect.left = PWLEFTMARG;
emdp->macrorect.bottom = PWMACROBOT;
emdp->macrorect.right = PWRIGHTMARG;
emdp->syslockrect.top = PWSYSLOCKTOP;
emdp->syslockrect.left = PWLEFTMARG;
emdp->syslockrect.bottom = PWSYSLOCKBOT;
emdp->syslockrect.right = PWRIGHTMARG;
emdp->kbdlockrect.top = PWKBDLOCKTOP;
emdp->kbdlockrect.left = PWLEFTMARG;
emdp->kbdlockrect.bottom = PWKBDLOCKBOT;
emdp->kbdlockrect.right = PWRIGHTMARG;
}
/* shift things around so a resized window looks ok */
prettyresize(dh, dv)
int dh;
int dv;
{
RgnPtr soldptr;
Rect eraser;
emdp->controlschanged = TRUE;
saveclip();
if (line25on(emdp)) {
EraseRect(&emdp->toprect);
InvalRect(&emdp->toprect);
}
/* erase the emulator portion of the window */
eraser.top = -4;
eraser.left = 0;
eraser.bottom = ((GrafPtr) emwindow)->portRect.bottom;
eraser.right = ((GrafPtr) emwindow)->portRect.right;
EraseRect(&eraser);
trackon = FALSE; /* show mouse tracking erased */
emdp->curson = FALSE; /* show cursor erased */
emdp->selrectvis = FALSE; /* selrection rectangle erased */
/* clear the line that forms the right hand box */
emdp->h19right += dh;
emdp->h19flagcenter += dh;
emdp->toprect.right += dh;
/* emdp->countrect stuff */
EraseRect(&emdp->countrect);
emdp->countrect.left += dh;
emdp->countrect.right += dh;
emdp->incountrect.left += dh;
emdp->incountrect.right += dh;
emdp->outcountrect.left += dh;
emdp->outcountrect.right += dh;
/* emdp->shrinkrect control */
emdp->shrinkrect.left += dh;
emdp->shrinkrect.right += dh;
/* initialize rectangles which frame items on the right */
emdp->shiftrect.left += dh;
emdp->shiftrect.right += dh;
emdp->dubshiftrect.left += dh;
emdp->dubshiftrect.right += dh;
emdp->macrorect.left += dh;
emdp->macrorect.right += dh;
emdp->syslockrect.left += dh;
emdp->syslockrect.right += dh;
emdp->kbdlockrect.left += dh;
emdp->kbdlockrect.right += dh;
#ifdef CLIPRESIZE
/* resize clip rect so new emulator area clipped properly */
soldptr = *soldclip;
SetRectRgn(soldclip, soldptr->rgnBBox.left, soldptr->rgnBBox.top,
(short) (soldptr->rgnBBox.right + dh),
(short) (soldptr->rgnBBox.bottom + dv) );
#endif
restoreclip();
}
/* copy the control rectangle contents into a bitmap for speedier redrawing */
copytoprect(thewind)
WindowPtr thewind;
{
Point corner;
RgnHandle tstRgn;
RgnHandle intRgn;
if (emwindow == NULL)
return;
/* check to make sure the top rectangle is completely visible */
if ((tstRgn = NewRgn()) == NULL)
return(0);
if ((intRgn = NewRgn()) == NULL) {
DisposeRgn(tstRgn);
return(0);
}
RectRgn(tstRgn, &emdp->toprect);
SectRgn(((GrafPtr) emwindow)->visRgn, tstRgn, intRgn);
if (! EqualRgn(tstRgn, intRgn)) {
/* the whole emdp->toprect is not visible on the screen, so don't copy */
DisposeRgn(tstRgn);
DisposeRgn(intRgn);
return(0);
}
DisposeRgn(tstRgn);
DisposeRgn(intRgn);
emdp->bmdestrect.top = emdp->toprect.top + 28;
emdp->bmdestrect.left = emdp->toprect.left + 2;
emdp->bmdestrect.bottom = emdp->toprect.bottom + 28;
emdp->bmdestrect.right = emdp->toprect.right + 2;
CopyBits(&((GrafPtr) thewind)->portBits, &emdp->toprectbm, &emdp->toprect, &emdp->bmdestrect,
srcCopy, (RgnHandle) NULL);
emdp->controlschanged = FALSE;
}
/* paste the saved contents into a bitmap */
pastetoprect(thewind)
WindowPtr thewind;
{
CopyBits(&emdp->toprectbm, &((GrafPtr) thewind)->portBits, &emdp->bmdestrect, &emdp->toprect,
srcCopy, (RgnHandle) NULL);
}
/* a terminal connection has been made, draw the controls */
termwake()
{
if (emwindow == NULL)
return;
emdp->controlschanged = TRUE;
InvalRect(&emdp->toprect);
}
drawq1controls()
{
struct fontsave ofont;
if (emwindow == NULL)
return;
savefont(&ofont);
DrawControls(emwindow);
restorefont(&ofont);
}
/* stubs for unused flag */
pfshowdubshift()
{
}
pfclrdubshift()
{
}